package xyz.naoyu.servlets.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import xyz.naoyu.dao.BaseDao;
import xyz.naoyu.entity.Item;
import xyz.naoyu.servlets.service.impl.BackCode;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yWieLoc
 * @date 2022/3/18 16:05
 */
public interface CurdService {


    default void edit(HttpServletRequest req, HttpServletResponse resp) {


    }

    default void show(HttpServletRequest req, HttpServletResponse resp) {

    }

    default void del(HttpServletRequest req, HttpServletResponse resp) {

    }

    default void list(HttpServletRequest req, HttpServletResponse resp) {
        BaseDao tools = new BaseDao();
        String type = req.getParameter("type");
        String a = req.getParameter("options");
        JSONObject options = JSONObject.parseObject(a);
        String res = tools.searchData(type,options);
        System.out.println(res);

        try {
            resp.getWriter().append(JSON.toJSONString(
                    new BackCode(true,"检索成功",res)
            ));
        } catch (Exception e) {
            e.printStackTrace();
        }


    }


}
